home *** CD-ROM | disk | FTP | other *** search
- /* clean.c - strip high-order bits & ctrl chars from text file */
- #include "stdio.h"
- #include "cminor.h"
-
- FILE *gfopen() ;
-
- main(argc,argv)
- int argc ; /* number of command line words */
- char *argv[] ; /* pointers to each word */
- {
- int c ;
- FILE *in ; /* use this file for input */
- FILE *out ; /* use this one for output */
- long nin , nout ; /* counts of chars in and out */
-
- if( argc < 3 ) /* be sure command line has enough words */
- { printf(" USAGE - clean input-file output-file \n");
- exit(1) ;
- }
-
- in = gfopen(argv[1],"r",ASC_MODE) ; /* open input file */
- if( in == NULL )
- { printf(" Can't open input file - %s \n",argv[1]) ;
- exit (2) ;
- }
-
- out = gfopen(argv[2],"w",ASC_MODE) ; /* open output file */
- if( out == NULL )
- { printf(" Can't open output file - %s \n",argv[2]) ;
- exit (3) ;
- }
-
- nin = 0 ;
- nout = 0 ;
- c = getc(in) ;
- while ( c != EOF ) /* get chars until end reached */
- { nin = nin + 1 ;
- c = c & 127 ; /* strip high-order bit */
- /* now see if it is a non-control char */
- /* or Carriage Return , Line Feed or Tab */
- if( ( (c >= ' ') && (c <='~') ) || (c == '\n')
- || (c == '\r') || (c == '\t') || (c == '\f') )
- { nout = nout +1 ; /* good char - output it */
- putc(c,out) ;
- }
- c = getc(in) ;
- }
- fclose(in) ;
- fclose(out) ;
- printf(" %10ld characters read \n",nin) ;
- printf(" %10ld characters written \n",nout) ;
- }